package com.example.gzysmartcity.ui.adapter;

import android.widget.CheckBox;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.gzysmartcity.R;
import com.example.gzysmartcity.repository.model.SellCar;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class SellCarRvAdpater extends BaseQuickAdapter<SellCar, BaseViewHolder> {
    private final List<Boolean> list;

    public void setCheck(boolean bool) {
        if (bool) {
            for (int i = 0; i < list.size(); i++) {
                setBoolList(i, true);
            }
        } else {
            for (int i = 0; i < list.size(); i++) {
                setBoolList(i, false);
            }
        }
    }

    public SellCarRvAdpater(int layoutResId, int size) {
        super(layoutResId);
        list = new ArrayList<>();
        for (int i = 0; i < size; i++) {
            list.add(false);
        }
    }


    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, SellCar sellCar) {
        ImageView imageView = baseViewHolder.getView(R.id.rv_sellCar_image);
        Glide.with(getContext()).load(sellCar.getPic()).into(imageView);
        baseViewHolder.setText(R.id.rv_sellCar_money, "¥" + sellCar.getMoney());
        baseViewHolder.setText(R.id.rv_sellCar_name, sellCar.getName());
        baseViewHolder.setText(R.id.rv_sellCar_num, sellCar.getNum() + "");
        CheckBox checkBox = baseViewHolder.getView(R.id.rv_sellCar_box);
        checkBox.setChecked(list.get(baseViewHolder.getLayoutPosition()));
    }


    public void setBoolList(int p, boolean bool) {
        list.set(p, bool);
    }


    public List<Boolean> getList() {
        return list;
    }

    public void notifyDataSetChangedWithRemove(int p) {
        list.remove(p);
        notifyDataSetChanged();
    }
}
